package com.df.hotfix.loader;

import javax.tools.SimpleJavaFileObject;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;

public class InputFileJavaFileObject extends SimpleJavaFileObject {

    String fileContent = null;

    /**
     * Construct a SimpleJavaFileObject of the given kind and with the
     * given URI.
     *
     * @param file      Java源文件
     * @param className 文件类型
     */
    public InputFileJavaFileObject(File file, String className) throws IOException {
        super(URI.create("string:///" + className.replace(".", "/") + ".java"), Kind.SOURCE);
        byte[] bytes = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
        this.fileContent = new String(bytes,"utf-8");
    }


    @Override
    public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
        return this.fileContent;
    }
}
